﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Gao.Poker.Command;
using Gao.Poker.Domain;
using Gao.Poker.Services;

namespace Gao.Poker.App.ViewModel
{
    public class GameTablesViewModel : INotifyPropertyChanged
    {
        private List<Tables> _TablesList;
        private Tables _tables;
        public Action<String> Message { get; set; }
        public TablesSaveCommand SaveCommand { get; set; }

        public GameTablesViewModel()
        {
            SaveCommand = new TablesSaveCommand(new Action<Boolean, Tables>(SaveResult));

        }

        private void SaveResult(bool obj, Tables member)
        {
            if (obj)
            {
                OnPropertyChanged("TablesList");
                if (Message != null)
                    Message("数据保存成功");
            }
        }

        public Tables Tables
        {
            get { return _tables ?? (_tables = new Tables()); }
            set
            {
                _tables = value;
                OnPropertyChanged("Tables");
            }
        }


        public List<Tables> TablesList
        {
            get
            {
                _TablesList = new TablesService().SearchTables();
                return _TablesList;
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
